var MemberWl = (function($) {

	var userIdModel = {
		name : 'user_id',
		index : 'user_id',
		width : 60,
		sorttype : "int",
		hidden : true

	};
	var userNameModel = {
		name : 'username',
		index : 'username',
		width : 60,
		sorttype : "string"
	};
	var memberWlModel = {
		name : 'member_win_lose',
		index : 'member_win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};

	var affiliateWlModel = {
		name : 'affiliate_win_lose',
		index : 'affiliate_win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	
	var affiliateCommissionModel = {
			name : 'affiliate_commission',
			index : 'affiliate_commission',
			width : 80,
			align : "right",
			sorttype : "float",
			formatter : 'currency'
		};
	var affiliateTotalModel = {
			name : 'affiliate_total',
			index : 'affiliate_total',
			width : 80,
			align : "right",
			sorttype : "float",
			formatter : 'currency'
		};
	return {
		initMemberWlEvent : function() {
			$("#submit").click(function() {
				MemberWl.bindMemberWl();
				return false;
			});
		},
		initMemberWl : function() {
			Affiliate.initDateRangePicker();
			MemberWl.initMemberWlEvent();
			MemberWl.bindMemberWl();
		},
		bindMemberWl : function() {

			var gridOption = $.extend(Affiliate.gridOption, {
				height : 500,
				colNames : [ 'User Id', 'User', 'MemberWL', 'AffiliateWl','Affiliate Comm','Affiliate Total' ],
				colModel : [ userIdModel, userNameModel, memberWlModel,
						affiliateWlModel,affiliateCommissionModel, affiliateTotalModel ]
			});

			$.blockUI();
			$.ajax( {
				type : "POST",
				url : "memberwlData",
				dataType : "json",
				data : {
					fromdate : $("#fromdate").val(),
					todate : $("#todate").val()
				},
				success : function(response) {
					// Show the grid
					gridOption.data = response.Main;
					gridOption.userData = response.Total;

					$("#jqgrid-table").jqGrid('GridUnload');
					$("#jqgrid-table").jqGrid(gridOption);
					Affiliate.initColumnChooser();
				},
				complete : function() {
					$.unblockUI()
				}
			});
		}

	};
})(jQuery);
